#include <QtGui>

#include "coneDialog.h"
#include "src/vector3d.h"

ConeDialog::ConeDialog(int _id, QWidget *_parent)
    : ObjectDialog(_id, _parent){
    setWindowTitle(QString::fromUtf8("Criando esfera ").append(QString::number(_id)));

    height = 1;
    radius = 1;

    createLayout();
}

ConeDialog::~ConeDialog(){
}

void ConeDialog::createLayout(){
    QDoubleSpinBox *heightDoubleSpinBox = new QDoubleSpinBox();
    heightDoubleSpinBox->setRange(0, 50.0);
    heightDoubleSpinBox->setSingleStep(1.0);
    heightDoubleSpinBox->setValue(height);
    connect(heightDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeHeight(double)));

    QHBoxLayout *heightLayout = new QHBoxLayout;
    heightLayout->addWidget(heightDoubleSpinBox);
    heightLayout->addStretch(1);

    QGroupBox *heightGroupBox = new QGroupBox(QString::fromUtf8("Altura"));
    heightGroupBox->setLayout(heightLayout);

    QDoubleSpinBox *radiusDoubleSpinBox = new QDoubleSpinBox();
    radiusDoubleSpinBox->setRange(0, 50.0);
    radiusDoubleSpinBox->setSingleStep(1.0);
    radiusDoubleSpinBox->setValue(radius);
    connect(radiusDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeRadius(double)));

    QHBoxLayout *radiusLayout = new QHBoxLayout;
    radiusLayout->addWidget(radiusDoubleSpinBox);
    radiusLayout->addStretch(1);

    QGroupBox *radiusGroupBox = new QGroupBox(QString::fromUtf8("Raio"));
    radiusGroupBox->setLayout(radiusLayout);

    QHBoxLayout *hLayout = new QHBoxLayout;
    hLayout->addWidget(heightGroupBox);
    hLayout->addWidget(radiusGroupBox);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(hLayout);
    mainLayout->addLayout(createColorButtonLayout());
    mainLayout->addStretch(1);

    setLayout(mainLayout);
}

void ConeDialog::acceptAndCreate(){

    if(!object){
        object = new Object(id);
        object->makeCone(height, radius, Color(colorR / 255.0, colorG / 255.0, colorB / 255.0, colorAlpha / 255.0));
    }
    else if(colorChanged)
    {
        object->setColor(Color(colorR / 255.0, colorG / 255.0, colorB / 255.0, colorAlpha / 255.0));
    }


    emit done(object, CYLINDER);
    accept();
}

void ConeDialog::changeHeight(double _h){
    height = _h;
}

void ConeDialog::changeRadius(double _r){
    radius = _r;
}
